package vmcs.customer.state;

import vmcs.controller.TransactionController;
import vmcs.store.CashStore;
import vmcs.store.Coin;
import vmcs.store.Store;

public class CoinInsertedState implements State {

	private TransactionController transactionController;
	private static CoinInsertedState instance;

	private CoinInsertedState(TransactionController transactionController) {
		this.transactionController = transactionController; 
	}

	public static CoinInsertedState getInstance(TransactionController transactionController) {
		if (instance == null) 
			instance = new CoinInsertedState(transactionController);
		return instance;
	} 

	@Override
	public void cancel() {

		//stop coin entry
		transactionController.getCoinReceiver().stopReceive();           

		//refund money so far entered
		transactionController.getCoinReceiver().refundCash();  

		//active drink selection
		transactionController.getDispenseController().allowSelection(true);

		transactionController.setState(transactionController.getIdleState());
	}

	@Override
	public void selectDrink(int selectedIdx) {
		// TODO Auto-generated method stub

	}

	@Override
	public void insertCoin(int value) {
		transactionController.setTotalInsertedCoins(transactionController.getTotalInsertedCoins()+value);
		if (transactionController.getTotalInsertedCoins() >= transactionController.getPrice()){
			transactionController.setState(transactionController.getEnoughCoinsInserted());
			transactionController.dispenseDrink();
		} else {
			transactionController.getCoinReceiver().continueReceive();
		}

	}


	@Override
	public void dispenseDrink(int drinkSelected) {
		// TODO Auto-generated method stub

	}

	@Override
	public void giveChange(int changeRequired) {
		// TODO Auto-generated method stub

	}

	@Override
	public void storeCash() {
		// TODO Auto-generated method stub

	}

	@Override
	public void terminateMachine() {
		// TODO Auto-generated method stub
		
	} 
}
